package cn.itcast.mq.listener;


import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

@Component
public class DirectExchangeListener {

//    可以通过@bena的方式进注入，这里我们采用@RabbitListenner的方式

    @RabbitListener(
            bindings = @QueueBinding(
                    value = @Queue(name = "direct.queue1"),//绑定的队列
                    exchange = @Exchange(name = "direct.exchange", type = ExchangeTypes.DIRECT),//绑定的交换机
                    key = {"red", "blue"} //绑定的key
            )
    )
    public void listenDirectQueue1(String msg) throws InterruptedException {
        System.out.println("listenDirectQueue1接收到的消息是：" + msg);
    }


    @RabbitListener(
            bindings = @QueueBinding(
                    value = @Queue(name = "direct.queue2"),//绑定的队列
                    exchange = @Exchange(name = "direct.exchange", type = ExchangeTypes.DIRECT),//绑定的交换机
                    key = {"red", "yellow"} //绑定的key
            )
    )
    public void listenDirectQueue2(String msg) throws InterruptedException {
        System.out.println("listenDirectQueue2接收到的消息是：" + msg);
    }
}
